clear all
set mem 50m
set more off

use "/Users/gwf25/Dropbox/research/religion/final code/religion_all.dta"

//  Begin definition of variables

***Drop subjects who thought the experiment was about religion
gen id = _n
drop if id == 98 | id == 176 | id == 194 | id == 383

***Drop subjects who incorrectly completed the priming task. This includes subjects who leave more than half the responses blank. The following subjects
***all left at least questions #2-#7 blank in the sentence unscrambling task. 
drop if id==7 | id==719 | id==740 | id==762 | id==940

***An error led to some subjects seeing both the control and religion salient sentence unscrambling tasks. Here, we drop those subjects.
drop if prime_diff == 1

***"skipped" is a dummy variable for whether subjects skip the question that asks their religion. If they skip this question, we drop them from the sample 
***and if not, we assign a dummy variable to indicate the treatment group (religion salient or control) that subject belongs to.
gen skipped=0
replace skipped=1 if  s10q15==""
gen treatR=.
replace treatR=religion if skipped==0
drop if skipped==1

***Define religion
gen relig=.

***Note: 1 = protestant or other christian, 2 = catholic, 3 = jewish, 4 = agnostic/atheist
replace relig=1 if (s10q15=="Christian - Other (please specify below)" | s10q15=="Christian - Protestant (please specify denomination below)")
replace relig=2 if s10q15=="Christian - Catholic"
replace relig=3 if s10q15=="Jewish (Orthodox/Reformed/etc.)" | s10q15=="Jewish (Orthodox/Reform/etc.)"
replace relig=4 if (s10q15=="Agnostic" | s10q15=="Atheist")

***Drop Mormon/Othodox Christians from the sample
drop if s10q15sp == "Greek Orthodox"
drop if s10q15sp == "Russian Othrodox"
drop if s10q15sp == "greek orthodox"
drop if s10q15sp == "Orthodox Christian"
drop if s10q15sp == "Greek Orthdox"
drop if s10q15sp == "christian orthodox"
drop if s10q15sp == "Greek Orthodox Christian"
drop if s10q15sp == "Russian orthodox"
drop if s10q15sp == "Church of Jesus Christ of Latter Day Saints"
drop if s10q15sp == "Greek Orthodox"

drop id
// End of variables

gen id = _n

***Create the divine punishment variable
gen divinepunish = s10q18sp4
egen divinepunish_std1 = std(divinepunish) if relig == 1
egen divinepunish_std2 = std(divinepunish) if relig == 2
egen divinepunish_std3 = std(divinepunish) if relig == 3
egen divinepunish_std4 = std(divinepunish) if relig == 4
gen divinepunish_std1_R = divinepunish_std1 * treatR if relig == 1
gen divinepunish_std2_R = divinepunish_std2 * treatR if relig == 2
gen divinepunish_std3_R = divinepunish_std3 * treatR if relig == 3
gen divinepunish_std4_R = divinepunish_std4 * treatR if relig == 4

***Create the median religious service attendance variable
gen religserv_freq = .
replace religserv_freq = 1 if s10q16 == "Never"
replace religserv_freq = 2 if s10q16 == "Less than once a month"
replace religserv_freq = 3 if s10q16 == "Once a month"
replace religserv_freq = 4 if s10q16 == "A few times a month"
replace religserv_freq = 5 if s10q16 == "Once a week"
replace religserv_freq = 6 if s10q16 == "A few times a week"
replace religserv_freq = 7 if s10q16 == "Once a day"
replace religserv_freq = 8 if s10q16 == "More than once a day"

egen median1 = median(religserv_freq) if relig == 1
gen religserv_freq1_median = .
replace religserv_freq1_median = 1 if religserv_freq > median1
replace religserv_freq1_median = 0 if religserv_freq <= median1

egen median2 = median(religserv_freq) if relig == 2
gen religserv_freq2_median = .
replace religserv_freq2_median = 1 if religserv_freq > median2
replace religserv_freq2_median = 0 if religserv_freq <= median2

egen median3 = median(religserv_freq) if relig == 3
gen religserv_freq3_median = .
replace religserv_freq3_median = 1 if religserv_freq > median3
replace religserv_freq3_median = 0 if religserv_freq <= median3

egen median4 = median(religserv_freq) if relig == 4
gen religserv_freq4_median = .
replace religserv_freq4_median = 1 if religserv_freq > median4
replace religserv_freq4_median = 0 if religserv_freq <= median4

gen religserv_freq1_median_R = treatR * religserv_freq1_median if relig == 1
gen religserv_freq2_median_R = treatR * religserv_freq2_median if relig == 2
gen religserv_freq3_median_R = treatR * religserv_freq3_median if relig == 3
gen religserv_freq4_median_R = treatR * religserv_freq4_median if relig == 4

***Public good contribution
rename s6 contribute

reg contribute treatR divinepunish_std1_R divinepunish_std1 if relig == 1, r
reg contribute treatR religserv_freq1_median_R religserv_freq1_median if relig == 1, r
reg contribute treatR divinepunish_std2_R divinepunish_std2 if relig == 2, r
reg contribute treatR religserv_freq2_median_R religserv_freq2_median if relig == 2, r



***Risk aversion

***Drop those subjects who don't take part in the risk preference section
drop if s3q1 == .

***Generate upper limit for risk with small amounts
gen risk1=.
replace risk1=(1.6*0.5-1) if s3q1==1
gen risk2=.
replace risk2=(2*0.5-1) if s3q2==1
gen risk3=.
replace risk3=(2.4*0.5-1) if s3q3==1
gen risk4=.
replace risk4=(2.8*0.5-1) if s3q4==1
gen risk5=.
replace risk5=(3.2*0.5-1) if s3q5==1
gen risk6=.
replace risk6=(3.6*0.5-1) if s3q6==1

***Choose the upper limit for the first time a subject chooses the risky asset with small amounts.
gen reservationrisk1= min(risk1,risk2,risk3,risk4,risk5,risk6)

***Generate upper limit for risk with large amounts
gen risk7=.
replace risk7=(160*0.5-100)/100 if s4q1==1
gen risk8=.
replace risk8=(200*0.5-100)/100 if s4q2==1
gen risk9=.
replace risk9=(240*0.5-100)/100 if s4q3==1
gen risk10=.
replace risk10=(280*0.5-100)/100 if s4q4==1
gen risk11=.
replace risk11=(320*0.5-100)/100 if s4q5==1
gen risk12=.
replace risk12=(360*0.5-100)/100 if s4q6==1

***Choose the upper limit for the first time a subject chooses the risky asset with large amounts.
gen reservationrisk2= min(risk7,risk8,risk9,risk10,risk11,risk12)

***Create two entries per subject. One is for small amounts and the other is for large amounts. riskchoice indicates whether it is a small or large stake gamble. 
reshape long reservationrisk, i(id) j(riskchoice)

***largestake is a dummy where a 1 indicates risk choices with large amounts and a 0 indicates risk choices with small amounts.
gen largestake=0
replace largestake= 1 if riskchoice==2 

***Recall reservationrisk indicates the upper limit. Rename this variable risku and create another variable, riskl, which will indicate the lower limit.
rename reservationrisk risk
gen riskl=.
gen risku=risk

***Fill in values for the lower limit.
***Note that even if someone always chose the safe option, they are assigned a missing value for the upper limit and the highest possible value we ask about for the lower limit. So they are properly taken care of.
replace riskl=. if risk < -.2
replace riskl=(1.6*0.5-1) if risk == 0
replace riskl=(2*0.5-1) if risk > .1 & risk < .3
replace riskl=(2.4*0.5-1) if risk > .3 & risk < .5
replace riskl=(2.8*0.5-1) if risk > .5 & risk < .7
replace riskl=(3.2*0.5-1) if risk > .7 & risk < .9
replace riskl=(3.6*0.5-1) if risk == . & s4q1 ~= .

intreg riskl risku treatR divinepunish_std2_R divinepunish_std2 largestake if relig==2, cluster(id)
intreg riskl risku treatR religserv_freq2_median_R religserv_freq2_median largestake if relig==2, cluster(id)
